//
//  Show.m
//  SDDataTest
//
//  Created by sodao on 12-9-19.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "Show.h"
#import "Dynamic.h"
#import "Person.h"
@implementation Show
@synthesize   isSampleInfo;
@synthesize   dynamic;
@synthesize   showId;
@synthesize   owner;
@synthesize   picUrl;
@synthesize   parsed;
@synthesize   commentNum;
@synthesize   comments;
@synthesize   favours;
@synthesize   location;
@synthesize   showDescription;
@synthesize   picSize;
@synthesize   parseCount;
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.dynamic forKey:kEncode_Dynamic];
    [aCoder encodeObject:self.showId forKey:kEncode_showID];
    [aCoder encodeObject:self.owner forKey:kEncode_owner];
    [aCoder encodeObject:self.picUrl forKey:kEncode_picurl];
    [aCoder encodeBool:self.parsed forKey:kEncode_parsed];
    [aCoder encodeInt32:self.commentNum forKey:kEncode_comCount];
    [aCoder encodeObject:self.comments forKey:kEncode_comments];
    [aCoder encodeObject:self.favours forKey:kEncode_favours];
    [aCoder encodeObject:self.location forKey:kEncode_location];
    [aCoder encodeObject:self.showDescription forKey:kEncode_picDesc];
    [aCoder encodeCGSize:self.picSize forKey:kEncode_picsize];
    [aCoder encodeInt32:self.parseCount forKey:kEncode_favCount];
    [aCoder encodeBool:self.isSampleInfo forKey:kEncode_isSample];
}
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super init]) {
        self.isSampleInfo = [decoder decodeBoolForKey:kEncode_isSample];
        self.dynamic = [decoder decodeObjectForKey:kEncode_Dynamic];
        self.showId = [decoder decodeObjectForKey:kEncode_showID];
        self.owner = [decoder decodeObjectForKey:kEncode_owner];
        self.picUrl = [decoder decodeObjectForKey:kEncode_picurl];
        self.parsed = [decoder decodeBoolForKey:kEncode_parsed];
        self.commentNum = [decoder decodeInt32ForKey:kEncode_comCount];
        self.comments = [decoder decodeObjectForKey:kEncode_comments];
        self.favours = [decoder decodeObjectForKey:kEncode_favours];
        self.location = [decoder decodeObjectForKey:kEncode_location];
        self.showDescription = [decoder decodeObjectForKey:kEncode_picDesc];
        self.picSize = [decoder decodeCGSizeForKey:kEncode_picsize];
        self.parseCount = [decoder decodeInt32ForKey:kEncode_favCount];
    }
    return self;
}
-(id)init{
    if (self = [super init]) {
        self.favours = [[NSMutableArray alloc] init];
        self.comments = [[NSMutableArray alloc] init];
        self.isSampleInfo = YES;
    }
    return self;
}
-(void)dealloc{
    [super dealloc];
    [self.dynamic release];
    [self.showId release];
    [self.owner release];
    [self.picUrl release];
    [self.comments release];
    [self.favours release];
    [self.location release];
    [self.showDescription release];
}

-(id)initWithDictionary:(NSDictionary *)dictionary{
    self = [super initWithDictionary:dictionary];
    if (self) {
        [self updateShowInfoByDictionary:dictionary];
    }
    return self;
}
-(void)updateShowInfoByDictionary:(NSDictionary*)dictionary{
    if (self.dynamic==nil) {
        self.dynamic = [[Dynamic alloc] initWithDictionary:dictionary];
    }else{
        
    }
    
    self.commentNum = [[dictionary objectForKey:@"commentcount"] intValue];
    self.parsed = [[dictionary objectForKey:@"favour"] boolValue];
    self.parseCount = [[dictionary objectForKey:@"favourcount"] intValue];
    self.picUrl = (NSString*)[dictionary objectForKey:@"picUrl"];
    self.location = (NSString*)[dictionary objectForKey:@"location"];
    self.showDescription = (NSString*)[dictionary objectForKey:@"picdesc"];
    NSArray* obj = (NSArray*)[dictionary objectForKey:@"picsize"];
    self.picSize = CGSizeMake([[obj objectAtIndex:0] intValue], [[obj objectAtIndex:1] intValue]);
    self.showId = [self getFeedIDByObject:[dictionary objectForKey:@"showId"]];
    self.isSampleInfo = NO;
}
@end
